<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php $mode= (isset($mode))? $mode:'';?>
<script type="text/javascript">
	<!--
		var wide_screen_stt = '<?php echo lang('ranking.wide_screen')?>';
		var normal_screen_stt = '<?php echo lang('ranking.normal_screen')?>';
		var login_first_warning = '<?php echo lang('ranking.user.login.alert');?>';

		var userObj = '<?php echo ($user);?>';
		sessionStorage.setItem('userObj',userObj);

		var page=2;
		var mode= '<?php echo $mode;?>'
	//-->

</script>

<?php
	if($this->uri->segment(2,'') == 'my_ranking'){
		$act2= ' act';
		$act1= '';
	}else{
		$act2= '';
		$act1= ' act';
	}

?>
<!-- Main content-->
<div class="wrap-content border" style="border-top:0;border-bottom:0;">
	<section id="ranking-zone">
		<!-- Left ranking-->
		<div id="left-rank-section">
			<nav id="rank-nav">
				<div class="rank-nav<?php echo $act1?>"><a href="<?php echo site_url('ranking');?>" class="public"><?php echo lang('ranking.rank_public');?></a></div>
<!--				<div class="rank-nav<?php echo $act2?>"><a href="javascript:void(0);" class="private" onclick="javascript:my_ranking();"><?php echo lang('ranking.rank_private');?></a></div>
-->
				<div id="button-screen-option"><input type="button" id="display_status_screen" value="" onclick="toogleScreen();" /></div>
			</nav>
			<div class="clrboth"></div>

			<!-- Rank header-->
			<div id="rank-header">
				<?php $titleF= (isset($titleF))? $titleF:'';	echo $titleF;?>
			</div>
			<div class="clrboth"></div>
			<!-- end rank header -->

			<!-- Ranking section-->
			<div id="vertical-align"></div>
			<div id="mcs_container">
				<div class="customScrollBox">
					<div class="container">
						<div class="content">

<!--							<div id="wide-screen"> &nbsp;
								<input type="button" id="display_status_screen" value="" onclick="toogleScreen();" />
							</div>
							<div class="clrboth"></div>
 -->
							<div class="row">
								<?php if(!empty($no_rank)):?>
									<?php
									/*	$array_search_rs = array();
										$i= 0 ;
										foreach ($no_rank as $array){
											if(isset($array['search_item']) AND $array['search_item']== ' search'){
												$array_search_rs[] = $array;
												unset($no_rank[$i]);
											}
											$i++;
										}
										if(!empty($array_search_rs)){
											$no_rank = array_values($no_rank);
										}
									*/
										$array_top_stand = array();
										$i= 0 ;
										foreach ($no_rank as $array){
											if( $array['is_top_stand']== 1){
												$array_top_stand[] = $array;
												unset($no_rank[$i]);
											}
											$i++;
										}
										if(!empty($array_search_rs)){
											$no_rank = array_values($no_rank);
										}

										$arr_temp= $arr_e= array();
										foreach ($no_rank as $one){ $arr_temp[]= $one['rank'];}
										$arr_e= array_values(array_unique($arr_temp));
										//foreach ($arr_temp as $key=>$val){$arr_e[]= $val;}

										$arr_no_ranking= $arr_top_ranking= $arr_other_ranking= array();

										foreach ($no_rank as $one){
											if($one['rank'] == $arr_e[0] ){
												$arr_no_ranking[] = $one;
											}elseif($one['rank'] == $arr_e[1] ){
												array_push($arr_top_ranking,$one);
											}else{
												$arr_other_ranking[]= $one;
											}
										}

										unset($no_rank);
										if(@$arr_no_ranking[0]['rank'] == 0)
											$no_rank= array_merge($arr_top_ranking,$arr_no_ranking,$arr_other_ranking);
										else
											$no_rank= array_merge($arr_no_ranking,$arr_top_ranking,$arr_other_ranking);

										if(!empty($array_top_stand)){
											$no_rank= array_merge($array_top_stand,$no_rank);
										}
								/*		$j= 0;$k= 0;
										foreach($no_rank as $one){
											if( isset($one['search_item']) AND $j== 0 ){
												$first_element = $one;
												$j++;
												break;
											}
											$k++;
										}
										if($j != 0){
											unset($no_rank[$k]);
											$no_rank = array_values ( array($first_element)+$no_rank );
										}
								*/
									//	if(!empty($array_search_rs)){
									//		$no_rank = array_merge($array_search_rs,$no_rank);
									//	}
									?>
									<?php $i= 0; $break_line= '';$j= 0;$iCount=0; ?>
									<?php foreach ($no_rank as $one):?>
										<?php
											if($i!= 0){
												if( ( $no_rank[$i]['rank'] != $no_rank[$i-1]['rank'] AND $no_rank[$i]['rank'] != 0 )  ){
													$break_line= '<div class="clrboth"></div>';
												}else{
													$break_line= '';
												}
											}
											if( $no_rank[$i]['is_top_stand'] == 1 ){
												$break_line3= '<div class="clrboth"></div>';
											}else{
												$break_line3= "";
											}
										/*	if($j %5 == 0){
												$break_line2= '<div class="clrboth"></div>';
											}else{
												$break_line2= '';
											} */
											$break_line2= '';
											$i++;
											if(isset($one['search_item']) AND $j == 0){
												$first_match = ' first_match';
												$j++;
											}else{
												$first_match= '';
											}

										?>
										<?php $rank_class= ($one['rank'] != 0)? 'draggable_rank':'draggable_no_rank'; ?>
										<?php $search_class= (isset($one['search_item']))? $one['search_item'] :''; ?>
									 	<?php $main_pic = $one['main_picture'] ;?>
										<?php $divID = "id_$iCount";$iCount++;?>
									 	<?php echo $break_line.$break_line2;?>
										<div class="<?php echo $rank_class;?> ui-widget-content<?php echo $search_class.$first_match;?>" rel="<?php echo $one['rank'];?>" id="<?php echo $divID;?>">
											<div class="dragDiv" draggable="true" onclick="open_POPUP(<?php echo $one['id'];?>);">
												<a href="javascript:void(0);" rel="<?php echo $one['id'];?>" class="info" id="link_<?php echo $one['id'];?>">
													<img rel="<?php echo $one['id'];?>" src="<?php echo site_url().'uploads/files/timthumb.php?w=72&h=72&zc=1&src='.site_url().'uploads/files/pictures/'.$one["image$main_pic"];?>" />
												</a>
											</div>
											<div class="clrboth"></div>
											<h3>
												<a href="javascript:void(0);" >
													<?php
														echo  display($one['name'],$max_ranking_name);
													 ?>
												</a>
											</h3>
										</div>
										<?php echo $break_line3;?>
									<?php endforeach;?>
							 	<?php endif;?>
							</div>

						</div>
					</div>
					<div class="dragger_container">
						<div class="dragger"></div>
					</div>
				</div>
				<!-- scroll buttons -->
				<a class="scrollUpBtn" href="#"></a>
				<a class="scrollDownBtn" href="#"></a>
			</div>

			<!--end ranking section-->

		</div>
		<!-- end left ranking-->

		<section id="rank-ladder"></section>

		<!-- Right ranking section-->
		<section id="right-rank-section">
			<nav id="rank-nav">
				<a href="javascript:void(0);"><?php echo lang('ranking.new_post');?></a>
			</nav>
			<div class="clrboth"></div>

			<div id="rank-post-div">
				<p><?php echo lang('ranking.post_question');?></p>
				<input type="button" class="green-button" value="<?php echo lang('ranking.send');?>" onclick="post_ranking();" />
			</div>
			<div class="clrboth"></div>

			<div id="post-ranks">
				<section id="hight-rank" >
					<div id="hight-rank-wrap">
					<!--	<div class="customScrollBox"></div>	-->
							<div class="container">
								<div class="content" id="dropable_high" >
								 	<div id="desc">
										<?php echo lang('ranking.high_rank_guider');?>
									</div>
								</div>
							</div>
							<div id="div_hide"></div>


					</div>
				</section>
				<div class="clrboth"></div>

				<section id="standard-rank" >
					<div id="standard-wrap">
						<div id="dropable_standard">
							<?php if(isset($item_inserted) AND !empty($item_inserted)):?>
								<?php $m_Pos = $item_inserted->main_picture; $m_img='image'.$m_Pos;$m_img = $item_inserted->$m_img; ?>
								<img rel="<?php echo $item_inserted->id?>" src="<?php echo site_url().'uploads/files/timthumb.php?w=70&h=70&zc=1&src='.site_url().'uploads/files/pictures/'.$m_img; ?>" />

								<script type="text/javascript">
									var id = <?php echo $item_inserted->id;?> ;
									sessionStorage.setItem('standard_rank_TEMP',id);
								</script>
							<?php else:?>
								<div id="desc">
									<?php echo lang('ranking.standard_rank_guider');?>
								</div>
							<?php endif;?>
						</div>

						<div class="clrboth"></div>
						<div id="button">
							<a href="javascript:void(0);" onclick="new_item();"><?php echo lang('ranking.post_new_item');?></a>
						</div>
					</div>
				</section>
				<div class="clrboth"></div>

			<section id="lower-rank" >
				<div id="lower-wrap">
				 	<div id="dropable_low">
						<div id="desc">
							<?php echo lang('ranking.lower_rank_guider');?>
						</div>
					</div>
					<div id="div_hide_lower_rank"></div>
				</div>
			</section>
			<div class="clrboth"></div>

			</div>
			<div class="clrboth"></div>

			<div id="facebook-right" >
				<div id="fb-root"></div>
				<script>(function(d){
					var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
					js = d.createElement('script'); js.id = id; js.async = true;
					js.src = "//connect.facebook.net/en_US/all.js#appId=229719387072808&xfbml=1";
					d.getElementsByTagName('head')[0].appendChild(js);
				}(document));</script>
				<div class="fb-like" data-href="http://karapos.com" data-send="false" data-width="180" data-show-faces="true"></div>
			</div>

		</section>
		<!-- end right ranking section-->
	</section>
</div>
<div class="clrboth"></div>
<!-- end main content -->

<script type="text/javascript">
	function my_ranking(){
		if(json_AUTHOR== null){
			$('#login_err_msg').dialog({
				 dialogClass: 'rank_alert',
				 buttons: [
					           {
					               text: "OK",
					               click: function() { $(this).dialog("close"); }
					           }
				           ]
				});
				for_ie();
			return false;
		}
		else{
			window.location = BASE_URI + 'ranking/my_ranking/';
		}
	}
</script>